﻿//using System.Collections.Immutable;
//using System.Linq;
//using Microsoft.CodeAnalysis;
//using Microsoft.CodeAnalysis.CSharp.Syntax;
//using Microsoft.CodeAnalysis.Diagnostics;
//using UIOC.CodeAnalysis.Helpers;

//namespace UIOC.CodeAnalysis.Suppressors;

//[DiagnosticAnalyzer(LanguageNames.CSharp)]
//internal sealed class AutowiredFieldSuppressor : DiagnosticSuppressor {

//    private static void LogInfo(string message) {
//        SourceOutputHelper.LogInfoToSourceGenLog(DiagnosticSeverity.Info, $"[{nameof(AutowiredFieldSuppressor)}] {message}");
//    }

//    private static readonly SuppressionDescriptor SuppressIDE0044 = new(
//        id: "SUPPRESS_IDE0044",
//        suppressedDiagnosticId: "IDE0044",
//        justification: "带有[Autowired]特性的私有字段不需要自动生成访问器");

//    public override ImmutableArray<SuppressionDescriptor> SupportedSuppressions =>
//        ImmutableArray.Create(SuppressIDE0044);

//    public override void ReportSuppressions(SuppressionAnalysisContext context) {
//        foreach (var diagnostic in context.ReportedDiagnostics) {
//            if (diagnostic.Id != "IDE0044")
//                continue;

//            var fieldDeclaration = diagnostic.Location.SourceTree?
//                .GetRoot(context.CancellationToken)
//                .FindNode(diagnostic.Location.SourceSpan)
//                .FirstAncestorOrSelf<FieldDeclarationSyntax>();

//            if (fieldDeclaration != null && IsAutowiredField(fieldDeclaration)) {
//                context.ReportSuppression(Suppression.Create(
//                    SuppressIDE0044,
//                    diagnostic));
//            }
//        }
//    }

//    // 判断字段是否带有[Autowired]特性
//    private bool IsAutowiredField(FieldDeclarationSyntax fieldDeclaration) {
//        // 检查字段是否有[Autowired]特性（忽略命名空间差异）
//        return fieldDeclaration.AttributeLists
//            .SelectMany(al => al.Attributes)
//            .Any(attr =>
//                attr.Name.ToString() == "Autowired" ||
//                attr.Name.ToString().EndsWith(".Autowired"));
//    }
//}
